<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    {js href='/public/static/jquery/jquery-1.11.0.min.js' /}
    {js href='/public/static/layui/layui.js' /}
    {CSS href="/public/static/layui/css/layui.css" /}
    {CSS href="__ADDONSTATIC__/css/style.css" /}

</head>
<body>
<div style="padding: 0px 10px;">
    <form class="layui-form" action="">

    <div class="layui-form-item">

        <table class="layui-table">
            <colgroup>
                <col width="60">
                <col width="120">
                <col>
                <col width="100">
            </colgroup>
            <thead>
            <tr>
                <th><input name="" lay-skin="primary" lay-filter="allChoose" type="checkbox"></th>
                <th>缩略图</th>
                <th>文章标题</th>
                <th>作者</th>
                <th>摘要</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data_list" id="v" }
            <tr>
                <td><input name="matids" value="{$v.id}" lay-skin="primary" type="checkbox"></td>
                <td><a href="{$v.cover}" target="_blank" ><img src="{$v.cover}" alt="" width="70" height="40" ></a></td>
                <td>{$v.title}</td>
                <td>{$v.author}</td>
                <td>{$v.digest}</td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {$page|raw}

    </div>
        <div class="layui-form-item">
            <label class="layui-form-label">添加到栏目</label>
            <div class="layui-input-block" style="width:500px;">
                <select name="columns" id="columns" required lay-verify="required" >
                    <option value=""></option>
                    {volist name="columns_list" id="v"}
                    <option  value="{$v.id}">{$v.name}</option>
                    {/volist}
                </select>

            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="button" onclick="location.href='{:addonUrl(\'article\')}'" class="layui-btn layui-btn-primary">返回</button>
            </div>
        </div>
    </form>

</div>
<script>

    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        form.on('submit(formDemo)', function (data) {
            var loadIndex = layer.load(1);
            var matids=[];
            $("input[name='matids']:checked").each(function (key,value) {
                matids[key]=$(this).val();
            });
            var columns = $("#columns option:selected").val();
            if(matids.length <= 0){
                parent.layer.msg('请选择素材');
            }
            $.post('', {matids:matids,columns:columns}, function (res) {
                layer.close(loadIndex);
                parent.layer.msg(res.msg);
            }).error(function (error) {
                parent.layer.alert('500 Internal Server Error');
                layer.close(loadIndex)
            });
            return false;
        });
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });


    });



</script>
</body>
</html>